<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 冒泡里=》外，捕获外向里 捕获阶段从最外层祖先元素（document）开始，逐级向内传播到目标元素。例如三个嵌套的div（div3 > div2 > div1）-->
    <style>
        #outer {
            width: 200px;
            height: 200px;
            background: red;
            padding: 20px;
        }
        
        #middle {
            width: 150px;
            height: 150px;
            background: blue;
            padding: 20px;
        }
        
        #inner {
            width: 100px;
            height: 100px;
            background: green;
        }
    </style>
</head>

<body>
    <div id="outer">
        <div id="middle">
            <div id="inner"></div>
        </div>
    </div>
    <script>
        let log = (phase, color) => console.log(`${color} ${phase}阶段`);

        document.getElementById('outer').addEventListener('click', () => log('捕获', '红色'), true);
        document.getElementById('middle').addEventListener('click', () => log('捕获', '蓝色'), true);
        document.getElementById('inner').addEventListener('click', () => log('捕获', '绿色'), true);

        document.getElementById('outer').addEventListener('click', () => log('冒泡', '红色'));
        document.getElementById('middle').addEventListener('click', () => log('冒泡', '蓝色'));
        document.getElementById('inner').addEventListener('click', () => log('冒泡', '绿色'));
    </script>
</body>

</html>